Mixed Content Elements

Mixed content elements are elements that can contain text and/or other elements.  This can get complicated in theory, but declaring them is not.  For example, let’s declare an element called <mixed.content> that can either contain data (PCDATA), or one of three elements called <one>, <two> and <three> respectively.  The syntax would be as follows:

<!ELEMENT mixed.content (#PCDATA | one | two | three)*>

There are a couple points to make note of when declaring mixed content elements.  First, the content model has to take the form of a single set of alternatives starting with #PCDATA followed by the element types that can occur.  Each element can be declared only once.  Second, the asterisk (*) after the closing parenthesis and before the closing > is not a typo.  You have to include the asterisk when declaring mixed content elements.

A Few Final Words on Elements

You now have the knowledge to create sophisticated element content models that have structure and integrity.  Believe it or not, we have just scratched the surface on the topic of DTD’s.  Now that you know how to declare elements, let’s look at declaring attributes within those elements.